﻿using HuaWei;
using HuaWei.CommClass;
using HuaWei.CommComp;
using HuaWei.Common;
using HuaWei.DAI;
using HuaWei.Windows.Forms;
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Windows.Forms;

internal class Class27
{
    public bool method(string _str)
    {
        if (JGLX.YZ.Equals(GParams._JGLX))
        {
            FrmRegSys sys = new FrmRegSys();
            if (!sys.CheckLicense(_str, "") && !sys.ShowDialog().Equals(DialogResult.OK))
            {
                return false;
            }
        }
        return true;
    }

    public bool method1()
    {
        FrmRegSys sys = new FrmRegSys();
        return sys.ShowDialog().Equals(DialogResult.OK);
    }

    private bool method2()
    {
        if (!GParams._JGLX.Equals(JGLX.GLY))
        {
            new DataSet();
            DBHelp.IniIDA();
            string sql = "select * from xmjbxxex";
            if (DBHelp.GetDt(sql, "temp").Rows.Count == 0)
            {
                if (GParams._JGLX.Equals(JGLX.CBR))
                {
                    return ((MsgBox.ShowQuestion("项目相关信息未导入，是否现在导入？") == System.Windows.Forms.DialogResult.OK) && Class37.smethod().imethod_1(false));
                }
                return ((MsgBox.ShowQuestion("请导入计量相关数据后继续当前操作！") == System.Windows.Forms.DialogResult.OK) && Class37.smethod().imethod_2(SJLX.JL));
            }
        }
        return true;
    }

    private bool method3(IDataAccess idataAccess, string _str)
    {
        string sql = "";
        DataSet dataSet = new DataSet();
        DataSet set2 = DHelp.ConvertXMLToDataSet(_str);
        try
        {
            idataAccess.OpenDatabase();
            idataAccess.BeginTrans();
            sql = "delete from ZZJGXX";
            DBHelp.ExeSql(idataAccess, sql);
            sql = "select * from ZZJGXX";
            Class39.smethod4(idataAccess, dataSet, sql, "ZZJGXX", true);
            DataTable sDt = set2.Tables["ZZJGXX"];
            DataTable tDt = dataSet.Tables["ZZJGXX"];
            DHelp.CopyDt(sDt, tDt);
            sql = "delete from XMJBXX";
            DBHelp.ExeSql(idataAccess, sql);
            sql = "select * from XMJBXX";
            Class39.smethod4(idataAccess, dataSet, sql, "XMJBXX", true);
            sDt = set2.Tables["XMJBXX"];
            tDt = dataSet.Tables["XMJBXX"];
            DHelp.CopyDt(sDt, tDt);
            idataAccess.Update(dataSet, true);
            idataAccess.Commit();
        }
        catch (Exception exception)
        {
            idataAccess.RollBack();
            MsgBox.ShowError("系统出错，请与管理员系统！", exception);
            return false;
        }
        finally
        {
            idataAccess.CloseDatabase();
        }
        return true;
    }

    private bool method4(string _str)
    {
        string pToDecrypt = "";
        if (File.Exists(_str))
        {
            try
            {
                StreamReader reader = new StreamReader(_str);
                string str2 = "";
                ArrayList list = new ArrayList();
                while (str2 != null)
                {
                    str2 = reader.ReadLine();
                    if (!((str2 == null) || str2.Equals("")))
                    {
                        list.Add(str2);
                    }
                }
                reader.Close();
                for (int i = 0; i < list.Count; i++)
                {
                    pToDecrypt = pToDecrypt + list[i].ToString();
                }
                string[] strArray = EncryptDecrypt.Decrypt(pToDecrypt, EncryptDecrypt.EncryptionType.DES).Split(new char[] { '|' });
                GParams._JGLX = (JGLX) Convert.ToInt16(strArray[0]);
                GParams.LoginId = strArray[1];
                string str3 = "";
                if (strArray.Length == 3)
                {
                    GParams.License = "1232312";
                    str3 = strArray[2];
                }
                else
                {
                    GParams.License = strArray[2];
                    str3 = strArray[3];
                }
                if (!this.method(GParams.License))
                {
                    MsgBox.ShowMsg("当前用户未注册，请联系供应商获取注册码！");
                    return false;
                }
                IDataAccess idataAccess = DBHelp.IniIDA();
                this.method3(idataAccess, str3);
                goto Label_0149;
            }
            catch (Exception exception)
            {
                MsgBox.ShowError("受权文件无效，请与软件供应商联系！", exception);
                return false;
            }
        }
        if (!this.method1())
        {
            return false;
        }
        this.method4(_str);
    Label_0149:
        return true;
    }

    public bool YfQclfhSo()
    {
        string str2 = (GParams.APP_PATH + @"xxb\").Replace(@"\\", @"\") + GParams._USERNAME + ".ltm";
        return this.method4(str2);
    }
}

